<!--  DIY Module Builder By HostJars http://opencart.hostjars.com -->
<div class="box">
	<div class="box-heading"><?php echo $filter["name"]; ?></div>
	<div class="box-content" style="text-align: center;">
		<form action="<?php echo $form_action; ?>" method="post">
		<?php
			foreach($filter["items"] as $item)
			{
				global $text_all_g,$text_yes_g,$text_no_g;
				$text_all_g=$text_all;
				$text_yes_g=$text_yes;
				$text_no_g=$text_no;
				$choices=($item["display"]=='select')?makeSelectBox($item):makeList($item);
				echo (!$choices)?'':<<<HTML
				<div style="font-weight:bold;font-size:120%;text-align:left;border-top: solid thin #ddd;border-bottom: solid thin #ddd;padding:3%">{$item["title"]}</div>
				<div style="margin-top:5%;margin-bottom:10%;text-align:left;font-weight:bold;">{$choices}</div>
HTML;
			}
		?>
		<input type="hidden" name="tfm_filter[name]" value="<?php echo $filter["name"] ?>">
		<input type="hidden" name="tfm_filter[settings][range_type]" value="<?php echo $filter["range_type"] ?>">
		<input type="hidden" name="tfm_filter[settings][range_id]" value="<?php echo $filter["range_id"] ?>">
		<input type="hidden" name="tfm_filter[settings][instock]" value="<?php echo $filter["instock"] ?>">
		<input type="hidden" name="tfm_filter[settings][filterroute]" value="<?php echo $filterroute ?>">
		<div><button style="width:100%;" type="submit"><?php echo $text_submit; ?></button></div>
	</div>
</div>
<?php
	
	function makeSelectBox($item)
	{
		global $text_all_g,$text_yes_g,$text_no_g;
		if(!$item["choices"])
		{
			return '';
		}
		$name_prefix='tfm_filter['.$item["item_type"].']['.(($item["item_type"]=="pf")?$item["product_field"]:$item["item_id"]).']';
		$select_name=$name_prefix.'[value]'.(($item["multiple"])?'[]':'');
		$multiple=($item["multiple"])?'multiple="multiple"':'';
		$range=($item["range"])?1:0;
		$opts=(!$multiple)?'<option value="tfmall">'.$text_all_g.'</option>':'';
		$attribute='';
		$bold=(isset($choice["master"]) && $choice["master"])?'style="font-weight:bold;"':'';
		
		foreach($item["choices"] as $choice)
		{
			$disabled=($choice["count"])?'':'disabled="disabled"';
			if($item["product_field"]=='shipping')
			{
				$choice["name"]=($choice["name"])?$text_yes_g:$text_no_g;
			}
			elseif($item["item_type"]!="pf")
			{
				$choice["value"]=$choice["name"];
			}
			if(isset($choice["attribute"]) && $choice["attribute"]!=$attribute)
			{
				$attribute=$choice["attribute"];
				$opts.='<optgroup label="'.$attribute.'">';
			}
			$opts.='<option '.$disabled.' '.$bold.' value="'.$choice["value"].'">'.$choice["name"].' ('.$choice["count"].')</option>';
		}
		
		return <<<HTML
		<select name="{$select_name}" {$multiple} style="width:90%;">
			{$opts}
		</select>
		<input type="hidden" value="{$range}" name="{$name_prefix}[range]">
HTML;
	}
	
	function makeList($item)
	{
		global $text_all_g,$text_yes_g,$text_no_g;
		if(!$item["choices"])
		{
			return '';
		}
		$name_prefix='tfm_filter['.$item["item_type"].']['.(($item["item_type"]=="pf")?$item["product_field"]:$item["item_id"]).']';
		$input_name=$name_prefix.'[value]'.(($item["multiple"])?'[]':'');
		$type=($item["multiple"])?'checkbox':'radio';
		$range=($item["range"])?1:0;
		$opts=(!$item["multiple"])?'<li style="list-style-type: none; text-align:left;"><input type="'.$type.'" value="tfmall" name="'.$input_name.'" checked="checked"><a style="text-decoration:none;" onclick="$(this).prev().click();" href="#">'.$text_all_g.'</a></li>':'';;
		$attribute='';
		$bold=(isset($choice["master"]) && $choice["master"])?'font-weight:bold;':'';
		
		foreach($item["choices"] as $choice)
		{
			$disabled=($choice["count"])?'':'disabled="disabled"';
			if($item["product_field"]=='shipping')
			{
				$choice["name"]=($choice["name"])?$text_yes_g:$text_no_g;
			}
			elseif($item["item_type"]!="pf")
			{
				$choice["value"]=$choice["name"];
			}
			if(isset($choice["attribute"]) && $choice["attribute"]!=$attribute)
			{
				$attribute=$choice["attribute"];
				$opts.='</ul>'.$attribute.'<ul style="padding-left: 10%; margin-top:0%;">';
			}
			$opts.='<li style="list-style-type: none; text-align:left;"><input '.$disabled.' type="'.$type.'" value="'.$choice["value"].'" name="'.$input_name.'"><a style="'.$bold.'text-decoration:none;" onclick="$(this).prev().click();"> '.$choice["name"].'&ensp;('.$choice["count"].')</a></li>';
		}
		
		return <<<HTML
		<ul style="padding-left: 10%; margin-top:0%;">
			{$opts}
		</ul>
		<input type="hidden" value="{$range}" name="{$name_prefix}[range]">
HTML;
	}
?>
<!--  /DIY Module Builder By HostJars http://opencart.hostjars.com -->